package ldh.im.handle;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import ldh.im.dto.base.ErrorResp;
import ldh.im.TransferData;
import ldh.im.util.JsonUtil;
import ldh.im.util.RandomCharacter;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;

@ChannelHandler.Sharable
public class ErrorHandler extends SimpleChannelInboundHandler<TransferData> {

//    private static final Logger LOGGER = LoggerFactory.getLogger(ErrorHandler.class);

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, TransferData transferData) throws Exception {
        if (transferData.getData().getClass() != ErrorResp.class) {
            ctx.fireChannelRead(transferData);
            return;
        }
        ErrorResp errorRec = (ErrorResp) transferData.getData();
//        LOGGER.info(String.format("服务器返回错误：%s", JsonUtil.toJson(errorRec)));


    }

    private String buildAuth(int length) {
        return RandomCharacter.getRandomCharacter(length);
    }
}
